<template>
  <div>
    <div class="forum-box">
      <div class="forum-box-ul">
        <el-tabs v-model="questionActive" @tabChange="handleClick()">
          <el-tab-pane v-for="item in questionTypeList" :label="item.label" :name="item.value" :key="item.value">
            <div class="forum-tab-content">
              <div class="forum-content-item" v-for="item in questionList" :key="item.id">
                <div class="forum-item-title">
                  <div class="community-sign" v-if="item.isTop">置顶</div>
                  <div class="community-sign-essence" v-if="item.isEss">精华
                  </div>
                  <a @click="$router.push(`/questionDetail/${item.id}`)" class="title-text ellipsis" target="_blank">{{ item.title }}</a>
                  <a v-for="tag in item.questionLabelList" :key="tag.id" class="topic-t">
                    <span>#{{ tag.name }}#</span>
                  </a>
                </div>
                <div class="forum-item-text">
                  <div v-html="item.content"></div>
                </div>
                <div class="forum-item-info clearfix">
                  <div class="forum-item-tag fl">
                    <span class="icon-box">
                      <el-icon size="20"><Comment /></el-icon>
                      {{ item.commentCount }}
                    </span>
                    <span class="icon-box">
                      <el-icon size="20"><View /></el-icon>
                       {{ item.clickCount }}
                    </span>
                  </div>
                  <div class="forum-text-date fr">
                    <span class="info-item">
                      {{ item.user.nickName }}
                      <span> 发布于：{{ item.createTime }}</span>
                    </span>
                  </div>
                </div>
              </div>
            </div>
          </el-tab-pane>
        </el-tabs>
        <div style="text-align: center; padding: 10px 0" v-if="total>10">
          <el-pagination background layout="prev, pager, next"
                         :current-page="pageNum"
                         :page-size="pageSize"
                         :total="total"
                         @update:current-page="changePageNum"
                          @current-change="getQuestionList"/>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getQuestionList } from "@/api/u/question.js";
export default {
  name: "home-center",
  data() {
    return {
      questionTypeList: [
        {label: "全部", value: 0},
        {label: "学习问答", value: 1},
        {label: "日常话题", value: 2},
        {label: "知识交流", value: 3}
      ],
      questionActive: 0,
      cateId: null,
      pageNum: 1,
      pageSize: 10,
      total: 0,
      questionList: [],
    };
  },
  computed: {
  },
  components: {

  },
  created() {
    this.getQuestionList()
  },
  methods: {
    // 切换页卡方法
    handleClick() {
      if (this.questionActive !== 0) {
        this.cateId = this.questionActive
      }
      this.current = 1;
      this.getQuestionList();
    },
    changePageNum(val){
      this.pageNum = val
    },
    // 获取问答列表方法
    getQuestionList(){
      let param = {
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        cateId: this.cateId
      }
      getQuestionList(param).then((res) => {
        this.questionList = res.data.list;
        this.total = res.data.total
      });
    }
  },
};
</script>

<style lang="scss" scoped>
.forum-box {
  padding: 20px 30px;
  background: #fff;
  border-radius: 10px;
  position: relative;
  .forum-box-ul {
    .forum-tab-content {
      .forum-content-item {
        width: 100%;
        border-bottom: 1px solid #ededed;
        padding: 22px 0;
        letter-spacing: normal;
        .forum-item-title {
          .community-sign {
            display: inline-block;
            width: 42px;
            height: 20px;
            line-height: 20px;
            font-size: 12px;
            font-weight: 400;
            color: #fff;
            border-radius: 10px;
            text-align: center;
            background: $theme-color-icon2;
            margin-right: 10px;
          }
          .community-sign-essence {
            display: inline-block;
            width: 42px;
            height: 20px;
            line-height: 20px;
            font-size: 12px;
            font-weight: 400;
            color: #fff;
            border-radius: 10px;
            text-align: center;
            background: $theme-color-icon;
            margin-right: 10px;
          }
          .title-text {
            font-size: 16px;
            color: #333;
            line-height: 21px;
            max-width: 450px;
            margin-right: 20px px;
            text-overflow: ellipsis;
            white-space: nowrap;
            overflow: hidden;
            font-weight: 700;
          }
          .topic-t {
            margin-left: 12px;
            line-height: 20px;
            font-size: 14px;
            font-weight: 400;
            color: #ff9e3f;
            cursor: pointer;
          }
        }
        .forum-item-text {
          font-weight: 400;
          margin: 16px 0 26px;
          color: #888;
          line-height: 22px;
          font-size: 14px;
          text-overflow: -o-ellipsis-lastline;
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-line-clamp: 2;
          line-clamp: 2;
          -webkit-box-orient: vertical;
        }
        .forum-item-info {
          .forum-item-tag {
            .icon-box {
              margin-right: 20px;
              color: #e2e2e2;
            }
          }
          .forum-text-date {
            line-height: 26px;
            color: #999;
            font-size: 12px;
          }
        }
      }
    }
  }
}
</style>